package com.qf.air.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * @version V1.0A
 * @uthor gpt
 * @Project air
 * @Package com.qf.air.util
 * @Description: ${TODO}
 * @Date 2021/11/1 11:27
 */
@Component
public class JedisUtils {

   @Autowired
   private JedisPool jedisPool;

   public Jedis getSource() {
      System.out.println("获取jedis");
      return jedisPool.getResource();
   }


   public void setEx(String key, int seconds, String value) {
      Jedis jedis = jedisPool.getResource();
      jedis.setex(key, seconds, value);
      jedis.close();
   }

   public void setEx(byte[] key, int seconds, byte[] value) {
      Jedis jedis = jedisPool.getResource();
      jedis.setex(key, seconds, value);
      jedis.close();
   }


   public void expire(String key, int seconds) {
      Jedis jedis = jedisPool.getResource();
      jedis.expire(key, seconds);
      jedis.close();
   }


   public void expire(byte[] key, int seconds) {
      Jedis jedis = jedisPool.getResource();
      jedis.expire(key, seconds);
      jedis.close();
   }

   public String get(String key) {
      Jedis jedis = jedisPool.getResource();
      String s = jedis.get(key);
      jedis.close();
      return s;
   }


   public byte[] get(byte[] key) {
      Jedis jedis = jedisPool.getResource();
      byte[] bytes = jedis.get(key);
      jedis.close();
      return bytes;
   }

}
